﻿using AbpOne.Domain;
using AbpOne.Domain.Configurations;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.EntityFrameworkCore.PostgreSql;
using Volo.Abp.EntityFrameworkCore.Sqlite;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.Modularity;


namespace AbpOne.EntityFrameworkCore {
    [DependsOn(
        typeof(AbpOneDomainModule),
        typeof(AbpEntityFrameworkCoreModule),
        typeof(AbpEntityFrameworkCoreMySQLModule),
        typeof(AbpEntityFrameworkCoreSqlServerModule),
        typeof(AbpEntityFrameworkCorePostgreSqlModule),
        typeof(AbpEntityFrameworkCoreSqliteModule)
    )]
    public class AbpOneFrameworkCoreModule : AbpModule {
        public override void ConfigureServices(ServiceConfigurationContext context) {
            context.Services.AddAbpDbContext<AbpOneDbContext>(builder => {
                builder.AddDefaultRepositories(includeAllEntities: true);
            });

            Configure<AbpDbContextOptions>(options => {
                switch (AppSettings.EnableDb) {
                    case "MySQL":
                        options.UseMySQL();
                        break;
                    case "SqlServer":
                        options.UseSqlServer();
                        break;
                    case "PostgreSql":
                        options.UseNpgsql();
                        break;
                    case "Sqlite":
                        options.UseSqlite();
                        break;
                    default:
                        options.UseMySQL();
                        break;
                }
            });
        }
    }
}